package com.future.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.future.domain.MediaResource;
import com.future.domain.vo.MediaResourceVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface MediaResourceMapper extends BaseMapper<MediaResource> {
    @Update("update media_resource set like_count = #{newCount} " +
            "where id = #{id} and like_count = #{oldCount}")
    int updateLikeCount(@Param("id") Long id,
                        @Param("oldCount")Long oldCount,
                        @Param("newCount")Long newCount);

    @Update("update media_resource set collection_count = #{newCollectionCount} " +
            "where id=#{targetId} and collection_count =#{collectionCount}")
    int updateCollectionCount(Long targetId, Long collectionCount,Long newCollectionCount);

    MediaResourceVO selectMediaResourceById(Long id);

    @Select("SELECT * FROM media_resource " +
            "WHERE (title LIKE CONCAT('%', #{keyword}, '%') " +
            "     OR content LIKE CONCAT('%', #{keyword}, '%')" +
            "     OR file_name LIKE CONCAT('%', #{keyword}, '%')" +
            "     OR file_type LIKE CONCAT('%', #{keyword}, '%')" +
            " ) " +
            "ORDER BY created_at DESC")
    Page<MediaResource> backgroundSearchMediaResources(Page<MediaResource> page, @Param("keyword") String keyword);
    @Select("SELECT * FROM media_resource " +
            "WHERE is_approved = 1 " +
            "AND (title LIKE CONCAT('%', #{keyword}, '%') " +
            "     OR content LIKE CONCAT('%', #{keyword}, '%')" +
            "     OR file_name LIKE CONCAT('%', #{keyword}, '%')" +
            "     OR file_type LIKE CONCAT('%', #{keyword}, '%')" +
            " ) " +
            "ORDER BY created_at DESC")
    Page<MediaResource> receptionSearchMediaResources(Page<MediaResource> page, @Param("keyword") String keyword);

    Page<MediaResourceVO> selectPendingMediaResources(Page<MediaResourceVO> page);
}